import Vue from 'vue'
import Vuex from 'vuex'
import { setStorage, getStorage } from '@/utils/storage'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: getStorage('token') || '',
    refresh_token: getStorage('refresh_token') || '',
    user: {} // 存储user对象
  },
  mutations: {
    setToken (state, token) {
      state.token = token
      setStorage('token', token)
    },
    setRefreshToken (state, refresh_token) {
      state.refresh_token = refresh_token
      setStorage('refresh_token', refresh_token)
    },
    setUser (state, userObj) {
      state.user = userObj
    },
    // 更改头像
    updatePhoto (state, photo) {
      state.user.photo = photo
    },
    updateName (state, userName) {
      state.user.name = userName
    }
  },
  actions: {
  },
  getters: {},
  modules: {
  }
})
